package com.kangye.learnteacher.controller;



import com.kangye.learnteacher.entity.Grade;
import com.kangye.learnteacher.service.GradeService;
import com.kangye.learnteacher.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    @RequestMapping("/getGrade")
    public ViewJsonObject<Grade> getGrade(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "limit",defaultValue = "1") Integer limit,String gradeNmae){
        ViewJsonObject<Grade> gradeList = gradeService.getGrade(page, limit,gradeNmae);
        return gradeList;
    }
    @RequestMapping("update")
    public Object update(Grade grade){
        /**
         * map集合，存储json列表
         */
        Map<String,Object> map = new HashMap<>();
        boolean fage = this.gradeService.upGrade(grade);
        if (fage){
            map.put("code",0);
            map.put("data","修改成功");
        }else {
            map.put("code",-1);
            map.put("data","修改失败");
        }
        return map;
    }
}
